var myModal = null
var valuearr = []

function getvalue(val) {
    if (val == "Menu_details") {
        window.location.href = "./Menu_details.html";
    }
    if (val == "Reservation Form") {
        window.location.href = "./Booking_info.html";
    }
    if (val == "Home") {
        window.location.href = "./index.html";
    }
    if (val == "Contact_Details") {
        window.location.href = "./Contact_Details.html";
    }
    if (val == "Gallery") {
        window.location.href = "./Gallery.html";
    }
}

function getElements(formId) {
    var form = document.getElementById(formId);
    var elements = new Array();
    var tagElements = form.getElementsByTagName('input');
    for (var j = 0; j < tagElements.length; j++) {
        elements.push(tagElements[j]);
    }
    var tagElements = form.getElementsByTagName('select');
    for (var j = 0; j < tagElements.length; j++) {
        elements.push(tagElements[j]);
    }
    var tagElements = form.getElementsByTagName('textarea');
    for (var j = 0; j < tagElements.length; j++) {
        elements.push(tagElements[j]);
    }
    return elements;

}

function confirm() {
    valuearr = []
    var isE = true;
    var arr = getElements('formId');

    arr.forEach((item) => {
        valuearr.push(item.value)
        if (!item.value) {
            isE = false
        }
    })

    if (isE === false) {
        alert('Please complete all forms before submitting!')
    } else {
        myModal = new bootstrap.Modal(document.getElementById('myModal'), {
            // backdrop: true,
            backdrop: 'static',
        })

        var addC = document.getElementById('Full Name');
        var textnode = document.createTextNode(`${valuearr[0]}${valuearr[1]}`);
        addC.appendChild(textnode);

        var addC1 = document.getElementById('E-mail');
        var textnode1 = document.createTextNode(`${valuearr[2]}`);
        addC1.appendChild(textnode1);

        var addC2 = document.getElementById('Phone');
        var textnode2 = document.createTextNode(`${valuearr[3]}`);
        addC2.appendChild(textnode2);

        var addC3 = document.getElementById('NumberGuest');
        var textnode3 = document.createTextNode(`${valuearr[4]}`);
        addC3.appendChild(textnode3);

        var addC4 = document.getElementById('Date');
        var textnode4 = document.createTextNode(`${valuearr[5]}`);
        addC4.appendChild(textnode4);

        var addC5 = document.getElementById('Time');
        var textnode5 = document.createTextNode(`${valuearr[6]}`);
        addC5.appendChild(textnode5);

        var addC6 = document.getElementById('TabelReservation');
        var textnode6 = document.createTextNode(`${valuearr[8]}`);
        addC6.appendChild(textnode6);

        var addC7 = document.getElementById('ReservationType');
        var textnode7 = document.createTextNode(`${valuearr[9]}`);
        addC7.appendChild(textnode7);

        var addC8 = document.getElementById('above');
        var textnode8 = document.createTextNode(`${valuearr[7]}`);
        addC8.appendChild(textnode8);

        var addC9 = document.getElementById('SpecialRequest');
        var textnode9 = document.createTextNode(`${valuearr[10]}`);
        addC9.appendChild(textnode9);
        myModal.show()
    }

}

function close() {
    valuearr = null;
    myModal.hide()
}

function submit() {
    myModal.hide()
    alert('Reservation successful!')
    window.location.href = "./Booking_info.html";

}